﻿using System;
using System.Collections.Generic;
using System.Linq;
using ud_Utilities;

namespace ud_gSDMS.Code_Service
{
    public class DBQLNS
    {
        readonly gSDMS_DataLinq db = new gSDMS_DataLinq();

        public List<ud_DM_GioiTinh> GetAllGioiTinh()
        {
            var result = from p in db.ud_DM_GioiTinhs
                         select p;
            return result.ToList();
        }

        public List<ud_DM_TinhThanh> GetAllTinhThanh()
        {
            var result = from p in db.ud_DM_TinhThanhs
                         select p;
            return result.ToList();
        }

        public List<ud_DM_TinhTrangHonNhan> GetAllHonNhan()
        {
            var result = from p in db.ud_DM_TinhTrangHonNhans
                         select p;
            return result.ToList();
        }
        public List<ud_DM_ChucVuHienTai> GetAllChucVuHienTai()
        {
            var result = from p in db.ud_DM_ChucVuHienTais
                         select p;
            return result.ToList();
        }
        public List<ud_DM_NganhDT> GetAllChuyenNganhDT()
        {
            var result = from p in db.ud_DM_NganhDTs
                         select p;
            return result.ToList();
        }
        public List<ud_DM_CongViecHienTai> GetAllCongViecHienNay()
        {
            var result = from p in db.ud_DM_CongViecHienTais
                         select p;
            return result.ToList();
        }
        public List<ud_DM_DanToc> GetAllDanToc()
        {
            var result = from p in db.ud_DM_DanTocs
                         select p;
            return result.ToList();
        }
        public List<ud_DM_HinhThucDT> GetAllHinhThucDT()
        {
            var result = from p in db.ud_DM_HinhThucDTs
                         select p;
            return result.ToList();
        }
        public List<ud_DM_MSChucDanh> GetAllMSChucDanh()
        {
            var result = from p in db.ud_DM_MSChucDanhs
                         select p;
            return result.ToList();
        }
        public List<ud_DM_NgoaiNgu> GetAllNgoaiNgu()
        {
            var result = from p in db.ud_DM_NgoaiNgus
                         select p;
            return result.ToList();
        }
        public List<ud_DM_LoaiCB> GetAllThuocLoaiCB()
        {
            var result = from p in db.ud_DM_LoaiCBs
                         select p;
            return result.ToList();
        }
        public List<ud_DM_TonGiao> GetAllTonGiao()
        {
            var result = from p in db.ud_DM_TonGiaos
                         select p;
            return result.ToList();
        }
        public List<ud_DM_TrinhDo> GetAllTrinhDo()
        {
            var result = from p in db.ud_DM_TrinhDos
                         select p;
            return result.ToList();
        }
        public List<ud_DM_QuocTich> GetAllCountry()
        {
            var result = from p in db.ud_DM_QuocTiches
                         select p;
            return result.ToList();
        }
            public List<ud_User> GetAllMemBer()
        {
            var result = from p in db.ud_Users
                         select p;
            return result.ToList();
        }
        public List<ud_QTLuong> getALLQTLuongOfPerson(int userid)
        {
            var result = from p in db.ud_QTLuongs
                             where p.UserID==userid && p.Active==true
                             select p;
            return result.ToList();
       }
       public bool checkUser(int userid)
        {
            var result = from p in db.ud_Users
                             where p.Active == true
                             select p;
            return (result.Count() != 0);
        }
       public List<ud_DM_MaNgach> getAllNgach()
       {
           var result = from p in db.ud_DM_MaNgaches where p.Active == true select p;
           return result.ToList();
       }
       public List<ud_DM_Bac> getAllBac(string ngach)
       {
           var result = from b in db.ud_DM_Bacs
                        from f in db.ud_NgachBacHes
                        where b.ID == f.DM_Bac && b.Active == true && f.ud_DM_MaNgach.Ngach == ngach
                        select b;
           return result.ToList();
       }
       public List<ud_DM_HeSo> getAllHeso(string ngach, string bac)
       {
           var result = from h in db.ud_DM_HeSos
                        from f in db.ud_NgachBacHes
                        where h.ID == f.DM_HeSo && h.Active == true && f.ud_DM_MaNgach.Ngach == ngach && f.ud_DM_Bac.Name==bac
                        select h;
           return result.ToList();
       }

       public List<ud_QTDT> getAllQTDTByUserID(int userid)
       {
           var result = from qt in db.ud_QTDTs where qt.UserID == userid && qt.Active == true select qt;
           return result.ToList();
       }

       public List<ud_DM_NganhDT> getAllNganhDT()
       {
           var result = from n in db.ud_DM_NganhDTs where n.Active == true select n;
           return result.ToList();
       }

       public List<ud_DM_HinhThucDT> getAllHinhthucDT()
       {
           var result = from ht in db.ud_DM_HinhThucDTs where ht.Active == true select ht;
           return result.ToList();
       }
       public List<ud_DM_BangCap> getAllBangCap()
       {
           var result = from b in db.ud_DM_BangCaps where b.Active == true select b;
           return result.ToList();
       }

       public void updateQTDT(int id, ud_QTDT ob)
       {
           var result = (from qt in db.ud_QTDTs where qt.ID == id select qt).First();
           result.NhapHoc = ob.NhapHoc;
           result.Active = ob.Active;
           result.DM_BangCap = ob.DM_BangCap;
           result.DM_HinhThucDT = ob.DM_HinhThucDT;
           result.DM_NganhDT = ob.DM_NganhDT;
           result.NoiDTBD = ob.NoiDTBD;
           result.TotNghiep = ob.TotNghiep;
           result.UpdatedBy = ob.UpdatedBy;
           result.UpdatedDate = ob.UpdatedDate;
           db.SubmitChanges();
           
       }
    }

}
